<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
        .el-main {
            position: absolute;
            height: 90%;
            width: 1920px;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }
    </style>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"><img src="../img/logo.png"></span>
                </a>
                <div class="right-menu">
                    <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                    <el-dropdown class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user2-160x160.jpg" class="user-avatar">
                            <!--Jay.Liu-->
                            {{username}}
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided>
                                <span style="display:block;" @click="updatepassword()">修改密码</span>
                            </el-dropdown-item>
                            <el-dropdown-item divided>
                                <a href="/logout.do"><span style="display:block;" @click="EXIT()">退出</span></a>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="menu in menuList" :index="menu.path">
                        <template slot="title">
                            <i class="fa" :class="menu.icon"></i>
                            {{menu.name}}
                        </template>
                        <template v-for="child in menu.children">
                            <el-menu-item :index="child.path">
                                <a :href="child.linkUrl" target="right">{{child.name}}</a>
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <iframe name="right" class="el-main" src="ordersetting.html" width="100%" height="580px"
                        frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>

    <!-- Form -->
    <!--<el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button>-->

    <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
        <el-form ref="UpdateCode" :model="form" :rules="rules">
                <el-form-item label="旧密码" :label-width="formLabelWidth" prop="oldcode">
                    <el-input v-model="form.oldcode" autocomplete="off" type="password"></el-input>
                </el-form-item>
            <el-form-item label="新密码" :label-width="formLabelWidth" prop="newcode">
                <el-input v-model="form.newcode" autocomplete="off" type="password"></el-input>
            </el-form-item>
            <el-form-item label="确认新密码" :label-width="formLabelWidth" prop="newcodeTo">
                <el-input v-model="form.newcodeTo" autocomplete="off" type="password"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="modify()">确 定</el-button>
        </div>
    </el-dialog>


</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script>
    new Vue({
        el: '#app',

        data: {

            username: "",
            menuList: [
                /*{
                    "path": "1",
                    "title": "工作台",
                    "icon": "fa-dashboard",
                    "children": []
                },
                {
                    "path": "2",
                    "title": "会员管理",
                    "icon": "fa-user-md",
                    "children": [
                        {
                            "path": "/2-1",
                            "title": "会员档案",
                            "linkUrl": "member.html",
                            "children": []
                        },
                        {
                            "path": "/2-2",
                            "title": "体检上传",
                            "children": []
                        },
                        {
                            "path": "/2-3",
                            "title": "会员统计",
                            "linkUrl": "all-item-list.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "3",
                    "title": "预约管理",
                    "icon": "fa-tty",
                    "children": [
                        {
                            "path": "/3-1",
                            "title": "预约列表",
                            "linkUrl": "ordersettinglist.html",
                            "children": []
                        },
                        {
                            "path": "/3-2",
                            "title": "预约设置",
                            "linkUrl": "ordersetting.html",
                            "children": []
                        },
                        {
                            "path": "/3-3",
                            "title": "套餐管理",
                            "linkUrl": "setmeal.html",
                            "children": []
                        },
                        {
                            "path": "/3-4",
                            "title": "检查组管理",
                            "linkUrl": "checkgroup.html",
                            "children": []
                        },
                        {
                            "path": "/3-5",
                            "title": "检查项管理",
                            "linkUrl": "checkitem.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "4",
                    "title": "健康评估",
                    "icon": "fa-stethoscope",
                    "children": [
                        {
                            "path": "/4-1",
                            "title": "中医体质辨识",
                            "linkUrl": "all-medical-list.html",
                            "children": []
                        },
                    ]
                },
                {
                    "path": "5",     //菜单项所对应的路由路径
                    "title": "统计分析",     //菜单项名称
                    "icon": "fa-heartbeat",
                    "children": [//是否有子菜单，若没有，则为[]
                        {
                            "path": "/5-1",
                            "title": "会员数统计",
                            "linkUrl": "report_member.html",
                            "children": []
                        },
                        {
                            "path": "/5-2",
                            "title": "套餐预约占比",
                            "linkUrl": "report_setmeal.html",
                            "children": []
                        },
                        {
                            "path": "/5-3",
                            "title": "运营数据统计",
                            "linkUrl": "report_business.html",
                            "children": []
                        }
                    ]
                }*/
            ],
            dialogFormVisible: false,
            form: {
                oldcode: '',
                newcode: '',
                newcodeTo: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            formLabelWidth: '120px',
            rules: {//校验规则
                newcode: [{ required: true, message: '新密码为必填项', trigger: 'blur' }],
                newcodeTo: [{ required: true, message: '确认密码为必填项', trigger: 'blur' }],
                oldcode: [{ required: true, message: '旧密码为必填项', trigger: 'blur' }]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.getusername();
        },
        methods: {
            // 修改密码(确定键)
            modify() {
                //console.log(this.form.newcode);
                //console.log(this.form.newcodeTo);
                var password = {
                    oldcode:this.form.oldcode,
                    newcode:this.form.newcode
                };
                this.$refs['UpdateCode'].validate((valid)=>{
                    if(valid){
                 //校验成功
                        //判断俩次新密码是否输入一致
                        if(this.form.newcode==this.form.newcodeTo){
                            //两次密码输入一致
                            //判断新密码是否与旧密码一致

                            if(this.form.oldcode!=this.form.newcode){
                                //两次密码输入一致,不与旧密码冲突,发送请求判断旧密码是否输入正确
                                axios.post("/user/updatepassword.do",password).then((res)=>{
                                    if(res.data.flag){
                                        //密码修改成功
                                        // this.$message({
                                        //     message:res.data.message,
                                        //     type:"success"
                                        // });
                                        this.dialogFormVisible = false;
                                        axios.get("/logout.do");
                                        setTimeout("window.location.href = '/pages/main.html'",3000);
                                        //location.reload(true);
                                        this.$alert('密码修改成功,3秒后自动跳转到登录页面!可以点击确定,立即跳转', '提示', {
                                            confirmButtonText: '确定',
                                            callback: action => {
                                                window.location.href = '/pages/login.html'
                                                // this.$message({
                                                //     type: 'info',
                                                //     message: `action: ${ action }`
                                                // });
                                            }
                                        });
                                        localStorage.removeItem("checkbox");
                                        localStorage.removeItem("username");
                                        localStorage.removeItem("password");
                                        localStorage.removeItem("usernamecheck");
                                        // ss


                                        //location.reload(true)
                                    }else {
                                        //密码修改失败
                                        this.$message.error(res.data.message)
                                    }

                                })
                            }else {
                                //旧密码与新密码不可以相同
                                this.$message.error("新密码不可以与旧密码相同")
                            }

                        }else {
                            this.$message.error("两次新密码输入不一致!请重新输入")
                        }
                        //console.log(1)
                    }else {
                        //校验失败
                        //console.log(2)
                        this.$message.error("请将修改密码表单填充完整!")
                    }


                });

            },

            //弹出修改密码
            updatepassword() {
                //console.log(1234)
                this.form.newcode=null;
                this.form.newcodeTo=null;
                this.form.oldcode=null;

                this.dialogFormVisible = true
            },
            //获取当前用户的用户名
            getusername() {
                axios.post("/user/getusername.do").then((res) => {
                    if (res.data.flag) {
                        this.username = res.data.data;
                        axios.post("/menu/findAll.do?username=" + this.username).then((resp) =>{
                            if (resp.data.flag){
                                this.menuList = resp.data.data;
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        });
                    } else {
                        this.$message.error(res.data.message)
                    }
                })
            },

            EXIT(){
                localStorage.setItem("exit", "yes");
            }
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
